# include <bits/stdc++.h>
# define MAXN 30023
using namespace std;
inline char getc() { 
    static char buf[1 << 18], *fs, *ft;
    return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}
inline int gn() { 
    int k = 0, f = 1;
    char c = getc();
    for(;!isdigit(c); c = getc()) if(c == '-') f = -1;
    for(; isdigit(c); c = getc()) k = k * 10 + c - '0';
    return k * f;
}

int last[4], f1[MAXN], f2[MAXN], a[MAXN], n, ans;

int main() { 
# ifndef LOCAL 
    freopen("egroup.in", "r", stdin);
    freopen("egroup.out", "w", stdout);
# else 
    freopen("in", "r", stdin);
# endif
    n = gn();
    for(int i = 1; i <= n; i++) a[i] = gn();
    for(int i = 1; i <= n; i++) { 
        for(int j = 1; j <= 3; j++) { 
            if(j <= a[i]) f1[i] = max(f1[i], f1[last[j]] + 1);
            if(j >= a[i]) f2[i] = max(f2[i], f2[last[j]] + 1);
        }
        last[a[i]] = i;
        ans = max(ans, max(f1[i], f2[i]));
    }
    printf("%d\n", n - ans);
}
